/*
 * Copyright (C) 2020 Baidu, Inc. All Rights Reserved.
 */
package com.wty.basic.errordemo;

import org.junit.Test;

import java.lang.reflect.InvocationTargetException;
import java.util.Arrays;

/**
 * @Author wangtengyu
 * @Date 2020/7/29 3:51 下午
 * @Description
 */
public class ReflectSon2 extends ReflectDemo<String> {

    @Override
    public void sayHello(String msg) {
        System.out.println("ReflectSon" + msg);
    }

    /**
     * 需要用isBridge 去掉父类的方法
     */
    @Test
    public void test2() {
        ReflectSon2 reflectSon2 = new ReflectSon2();
        Class clazz = reflectSon2.getClass();
        Arrays.stream(clazz.getMethods()).filter(item -> item.getName().equals("sayHello") && !item.isBridge()).forEach(method -> {
            try {
                method.invoke(reflectSon2, "world");
            } catch (IllegalAccessException e) {
                e.printStackTrace();
            } catch (InvocationTargetException e) {
                e.printStackTrace();
            }
        });

    }
}
